package com.lei.datastructure.stack;

import com.lei.datastructure.linkedlist.LinkedList;

/**
 * @Author LeiXiaoLei
 * @Date 2022/7/22 16:03
 * @Version 1.0
 */
public class LinkedListStack<E> implements Stack<E> {

    private final LinkedList<E> list;

    public LinkedListStack() {
        this.list = new LinkedList<>();
    }

    @Override
    public int getSize() {
        return list.getSize();
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }

    @Override
    public E pop() {
        return list.removeFirst();
    }

    @Override
    public E peek() {
        return list.getFirst();
    }

    @Override
    public void push(E e) {
        list.addFirst(e);
    }

    @Override
    public String toString() {
        return "LinkedListStack{" +
                "list=" + list +
                '}';
    }
}
